package ee.rsi2m.goproject.util;

import java.util.ArrayList;
import java.util.List;


import ee.rsi2m.goproject.model.GoBoard;
import ee.rsi2m.goproject.model.GoGroup;
import ee.rsi2m.goproject.model.GoStone;
import ee.rsi2m.goproject.service.GoStoneFactory;

public class GoGroupUtils {
	
	public static List<GoStone> getStoneListToRegroup(List<GoGroup> goGroupList) {
		List<GoStone> goStoneList = new ArrayList<GoStone>();

		for (GoGroup group : goGroupList) {
			goStoneList.addAll(group.getStones());
		}

		return goStoneList;

	}
	
	public static GoGroup getBiggestGroup(List<GoGroup> groupList) {
		GoGroup biggestGroup = null;
		for (GoGroup group : groupList) {
			if (biggestGroup == null) {
				biggestGroup = group;
			}
			if (group.getSize() > biggestGroup.getSize()) {
				biggestGroup = group;
			}
		}
		return biggestGroup;

	}
	
	public static List<GoStone> getFourNeighboursStoneList(GoStone stone, GoBoard board) {
		List<GoStone> stoneList = new ArrayList<GoStone>();

		GoStone downStone = GoStoneFactory.getStone(board,
				stone.getRelativeX(), stone.getRelativeY() - 1);
		GoStone upStone = GoStoneFactory.getStone(board, stone.getRelativeX(),
				stone.getRelativeY() + 1);
		GoStone rightStone = GoStoneFactory.getStone(board,
				stone.getRelativeX() - 1, stone.getRelativeY());
		GoStone leftStone = GoStoneFactory.getStone(board,
				stone.getRelativeX() + 1, stone.getRelativeY());
		
		stoneList.add(downStone);
		stoneList.add(upStone);
		stoneList.add(rightStone);
		stoneList.add(leftStone);
		
		return stoneList;

	}

}
